﻿<%
	Session("bChucnang")=3
	Session("FormName")="F19"
%>
<!--#include file="..\CheckSession.inc"-->	
<%
	
	bNgayIn=Request("NgayIn")
	bInForDate=false
	ChonSql=false
	Set Cls=server.CreateObject("Vinalines.ClsFunction")
	bSTT=trim(Request("bSTT"))
	if bSTT="" or bSTT="null" or (not isnumeric(bSTT)) then bSTT=1
	sNgaythang=""
%>
<HTML>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<TITLE>Quản Trị Văn Thư</TITLE>
<style type="text/css">
<!--
	br.page { page-break-before: always; }
-->
</style>
<script language=vbscript runat=server>
function strBreakLine(strLine)
		intVt=instr(1,strLine,"@")
		if intVt > 10 then
			strBreakLine=mid(strLine,1,10)+ " <br> "
			strline2=mid(strLine,11,len(strLine))
			if len(strline2) > 8 then
				strBreakLine=strBreakLine + mid(strline2,1,8)+" <br> "+mid(strline2,9,len(strline2))
			end if
		else
			if intVt > 0 then
				strBreakLine=mid(strLine,1,intVt-1)+ " <br> "
				str1 = mid(strLine,intVt,len(strLine))
				if len(str1) > 8 then
					str2=mid(str1,1,8)+ " <br> " + mid(str1,9,len(str1))
				else
					str2=str1
				end if
				strBreakLine=strBreakLine + str2
			else
				strBreakLine=mid(strLine,1,8)+ " <br> " + mid(strLine,9,len(strLine))
			end if
		end if
end function
function strBreakLineDonVi(strLine)
		strLine=trim(strLine)
		intdc=0
		if len(strLine) > 7 then
			intdc=instr(1,strLine," ")
			if intdc > 0 then
				strBreakLineDonVi=strLine
			else
				strBreakLineDonVi=mid(strLine,1,7)+ " <br> " + mid(strLine,8,len(strLine)-7)
			end if
		else
			strBreakLineDonVi=strLine
		end if
end function
Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function
</script>
<Body style="font-family:Times new roman" topmargin=0 leftmargin=0>
<Center>
<form name=frm method=post>
		<!--<P align=left><font face="Times New Roman" size="2"><B><%=Application("bTenDonVi")%></B></font>-->
		<P align=center><font face="Times New Roman" size="4"><B>TỔNG HỢP CÔNG VĂN ĐẾN</B></font>
		<br>
			<% if  Session("VTDenFrom")<>"" and Session("VTDenTo") <>"" then %>
				Từ ngày <%=Session("VTDenFrom")%> đến ngày	<%=Session("VTDenTo")%>
			<%end if%>
		<br>		
		<%
		if bNgayIn <> "" then
			if session("bIn")<>"OFF" then
				Set RecCheck=server.CreateObject("ADODB.Recordset")
				RecCheck.CursorType=3
				RecCheck.CacheSize=5
				ssql="select * from incongvan where ngaycongvan < '" & savedate(bNgayIn) & "' and loaicongvan=1 order by ngaycongvan desc"
				RecCheck.Open sSQL,Conn
				if RecCheck.recordcount > 0 then
					ChonSql=true
				end if
				RecCheck.movefirst
				if not RecCheck.eof then
					strNgayTruoc=Formatdate(RecCheck("ngaycongvan"))
				end if
				intsothang=cint(mid(trim(cstr(bNgayIn)),4,2))-cint(mid(trim(cstr(strNgayTruoc)),4,2))
					intSoCongVan=RecCheck("socongvancuoi")
					intSoTrang=RecCheck("sotrangcuoi")
					if ChonSql=true then
						sSQL="select * from vtden where (ngaynhan = '" & savedate(strNgayTruoc) & "' and soghinhan >= " & cint(intSoCongVan) & ") or (ngaynhan > '" & savedate(strNgayTruoc) & "' and ngaynhan <='" & savedate(bNgayIn) & "')  order by nguoinhan,ngaynhan,len(soghinhan),soghinhan"
					else
						sSQL="select * from vtden where ngaynhan ='" & savedate(bNgayIn) & "' order by nguoinhan,ngaynhan,len(soghinhan),soghinhan"
					end if
					if intsothang=0 then
						oldnumberpage=cint(intSoTrang)
					else
						oldnumberpage=1
					end if
				RecCheck.close
				set RecCheck = nothing
				bInForDate=true
			else
			sSQL=Request("PrintValue") 
			sSQL=sSQL+" order by nguoinhan,ngaynhan,len(soghinhan),soghinhan"
			oldnumberpage=1
			end if
		else
				sSQL=Request("PrintValue") 
				sSQL=sSQL+" order by nguoinhan,ngaynhan,len(soghinhan),soghinhan"
				oldnumberpage=1
		end if
			sheightbang="670px"
			sheightdong="45px"
			Set RecCB=server.CreateObject("ADODB.Recordset")
			RecCB.CursorType=3
			RecCB.CacheSize=5
			RecCB.Open sSQL,Conn
			chktstrang=round(RecCB.recordcount/12-0.5)
			cnt=1
			count=1
			numberpage=oldnumberpage
			if numberpage=0 then
				numberpage=1
			end if
			tstrang=1
			if chktstrang < 1 then
			%>
	
			<Table border="2" width="100%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111" >
			<TR height="50px">	
				<TD  width=5% align=center ><font size="2"><strong>STT</strong></font></TD>	
				<TD width=10% align=center ><font size="2"><strong>Số công văn</strong></font></TD>
				<TD width=5% align=center ><font size="2"><strong>Ngày CV</strong></font></TD>
				<TD width=20% align=center ><font size="2"><strong>Nơi gửi</strong></font></TD>				
				<TD width=30% align=center ><font size="2"><strong>Trích yếu nội dung</strong></font></TD>
				<TD width=20% align=center nowrap><font size="2"><strong>Đơn vị hoặc<br>người nhận</strong></font></TD>
				<TD width=10% align=center nowrap><font size="2"><strong>Ký nhận</strong></font></TD>
			</TR>			
			<%
			else
			%>
			<Table border="2" width="100%" height="<%=sheightbang%>" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111" >
			<TR height="50px">	
				<TD  width=5% align=center ><font size="2"><strong>STT</strong></font></TD>	
				<TD width=10% align=center ><font size="2"><strong>Số công văn</strong></font></TD>
				<TD width=5% align=center ><font size="2"><strong>Ngày CV</strong></font></TD>
				<TD width=20% align=center ><font size="2"><strong>Nơi gửi</strong></font></TD>				
				<TD width=30% align=center ><font size="2"><strong>Trích yếu nội dung</strong></font></TD>
				<TD width=20% align=center nowrap><font size="2"><strong>Đơn vị hoặc<br> người nhận</strong></font></TD>
				<TD width=10% align=center nowrap><font size="2"><strong>Ký nhận</strong></font></TD>
			</TR>			
			<%
			end if
			RecCB.movefirst
			cnsoghinhan=RecCB("soghinhan")
			Do while not RecCB.EOF
				if (cnt/2=int(cnt/2)) then
					color="#eeeecc"
				else
					color="#F8F9D9"
				end if
				color="white"
			if count > 12 then
				cnsoghinhan=RecCB("soghinhan")
				Response.Write "</table>"
				response.write "<br class=""page"" />"
				count=1
				numberpage=numberpage+1
				tstrang=tstrang+1
			if  tstrang > chktstrang then
			%>
			<Table border="2" width="100%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111" height="43" >	
			<TR height="50px">
				<TD  width=5% align=center height="27" ><font size="2"><strong>STT</strong></font></TD>	
				<TD width=10% align=center height="27" ><font size="2"><strong>Số công văn</strong></font></TD>
				<TD width=5% align=center height="27" ><font size="2"><strong>Ngày CV</strong></font></TD>
				<TD width=20% align=center height="27" ><font size="2"><strong>Nơi gửi</strong></font></TD>				
				<TD width=30% align=center height="27" ><font size="2"><strong>Trích yếu nội dung</strong></font></TD>
				<TD width=20% align=center nowrap height="27"><font size="2"><strong>Đơn vị hoặc<br> người nhận</strong></font></TD>
				<TD width=10% align=center nowrap height="27"><font size="2"><strong>Ký nhận</strong></font></TD>
			</TR>			
			<TR bgcolor="<%=color%>" height="<%=sheightdong%>">	
				<TD width=5% align=center height="15"><font size="2"><%=bSTT%></font></TD>
				<TD width=10% height="15" ><font size="2"><%=RecCB("sogoc")%>&nbsp;</font></TD>
				<TD width=5% align=center height="15"><font size="2"><%=cls.FormatDate(RecCB("ngayky"))%>&nbsp;</font></TD>
				<TD width=20% align=center height="15"><font size="2"><%=RecCB("doitac")%>&nbsp;</font></TD>				
				<TD width=30% height="15" ><font size="2"><%=RecCB("Trichyeu")%>&nbsp;</font></TD>
				<TD width=20% height="15" ><font size="2"><%=RecCB("nguoinhan")%>&nbsp;</font></TD>
			</TR>
			<%
			else
			%>
			<Table border="2" width="100%" height="57" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111" >
			<TR height="50px">	
				<TD  width=5% align=center height="30" ><font size="2"><strong>STT</strong></font></TD>	
				<TD width=10% align=center height="30" ><font size="2"><strong>Số công văn</strong></font></TD>
				<TD width=5% align=center height="30" ><font size="2"><strong>Ngày CV</strong></font></TD>
				<TD width=20% align=center height="30" ><font size="2"><strong>Nơi gửi</strong></font></TD>				
				<TD width=30% align=center height="30" ><font size="2"><strong>Trích yếu nội dung</strong></font></TD>
				<TD width=20% align=center nowrap height="30"><font size="2"><strong>Đơn vị hoặc<br> người nhận</strong></font></TD>
				<TD width=10% align=center nowrap height="30"><font size="2"><strong>Ký nhận</strong></font></TD>
			</TR>			
			<TR bgcolor="<%=color%>" height="<%=sheightdong%>">	
				<TD width=5% align=center height="15"><font size="2"><%=bSTT%></font></TD>
				<TD width=10% height="10" ><font size="2"><%=RecCB("sogoc")%>&nbsp;</font></TD>
				<TD width=5% align=center height="10"><font size="2"><%=cls.FormatDate(RecCB("ngayky"))%>&nbsp;</font></TD>
				<TD width=20% align=center height="10"><font size="2"><%=RecCB("doitac")%>&nbsp;</font></TD>				
				<TD width=30% height="10" ><font size="2"><%=RecCB("Trichyeu")%>&nbsp;</font></TD>
				<TD width=20% height="10" ><font size="2"><%=RecCB("nguoinhan")%>&nbsp;</font></TD>
			</TR>
			<%
			end if
			else
			%>
			<TR bgcolor="<%=color%>" height="<%=sheightdong%>">
				<TD width=5% align=center height="15"><font size="2"><%=bSTT%></font></TD>	
				<TD width=10% height="15" ><font size="2"><%=RecCB("sogoc")%>&nbsp;</font></TD>
				<TD width=5% align=center height="15"><font size="2"><%=cls.FormatDate(RecCB("ngayky"))%>&nbsp;</font></TD>
				<TD width=20% align=center height="15"><font size="2"><%=RecCB("doitac")%>&nbsp;</font></TD>				
				<TD width=30% height="15" ><font size="2"><%=RecCB("Trichyeu")%>&nbsp;</font></TD>
				<TD width=20% height="15" ><font size="2"><%=RecCB("nguoinhan")%>&nbsp;</font></TD>
				<TD width=5% >&nbsp;</TD>				
			</TR>		
			<%
			end if
				RecCB.MoveNext
				count=count+1
				cnt=cnt+1
				bSTT=bSTT+1
			Loop
			if bInForDate=true and chktstrang >= 1 then
				chkSql="delete from incongvan where ( ngaycongvan='" & savedate(bNgayIn) & "' and loaicongvan =1 ) or ( ngaycongvan < '" & dateadd("m",-1,date) & "' and loaicongvan =1 ) "
				conn.Execute chkSql
				chkSql="insert into incongvan(ngaycongvan,socongvancuoi,sotrangcuoi,loaicongvan) values ( '" & savedate(bNgayIn) & "'," & cint(cnsoghinhan) & "," & numberpage & ",1)"
				conn.Execute chkSql
			end if
		%>
	</Table>
</Form>
</Center>
<Body>
<%
	Cls=nothing
	Conn.Close
	Set Conn=nothing
%>
</HTML>